﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Hazop
{
    public partial class LoginForm : Form {
        private int loginCount;
        public const int MAX_LOGIN_COUNT = 3;
        public LoginForm()
        {
            InitializeComponent();
            CenterToScreen();
            loginCount = 0;
        }

        private void btnSubmit_Click(object sender, EventArgs e) {
            if (tbxUserName.Text.Equals("admin")&&tbxPassword.Text.Equals("admin"))
            {
                this.DialogResult = DialogResult.OK;
            }
            else {
                loginCount++;
                if (loginCount == MAX_LOGIN_COUNT)
                    this.DialogResult = DialogResult.Cancel;
                else {
                    MessageBox.Show("用户名或密码不正确!");
                    tbxUserName.Focus();
                    this.DialogResult = DialogResult.None;
                }
            }
           
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e) {
            this.DialogResult = DialogResult.Cancel;
        }

        private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if(this.DialogResult != DialogResult.Cancel && this.DialogResult != DialogResult.OK) {
                e.Cancel = true;
            }
        }
    }
}
